package com.dd.shop4j.website.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.dd.shop4j.goods.model.GoodsInfo;
import com.dd.shop4j.website.goods.service.GoodsInfoService;

@Controller
@RequestMapping("/good/detail")
public class GoodDetailsController {

	@Resource GoodsInfoService goodsInfoService;
	
	@RequestMapping("/{goodId}")
	public ModelAndView init(@PathVariable("goodId") Integer goodId) {
		ModelAndView view = new ModelAndView("/website/good_detail");
		GoodsInfo good = goodsInfoService.getGoodsInfo(goodId);
		view.addObject("good", good);
		view.addObject("brand", goodsInfoService.getGoodsBrandById(good.getBrandId()));
		view.addObject("desc", goodsInfoService.getGoodsDescription(goodId));
		view.addObject("images", goodsInfoService.getGoodsImagesByGoodId(goodId));
		return view;
	}
	
}
